Page({
  data: {
    inputValue: '',
    messages: [],
    userAvatar: 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0',
    keyboardHeight: 0
  },

  onInputChange(e) {
    this.setData({
      inputValue: e.detail.value
    });
  },

  onInputFocus(event) {
    // 监听键盘高度变化
    let height = event?.detail?.height || 0;
    this.setData({
      keyboardHeight: height-10
    })
  },
  onInputBlur() {
    this.setData({
      keyboardHeight: 0
    });
  },

  handleSubmit() {
    let content = this.data.inputValue;
    if (!content || content.trim() === '') {
      wx.showToast({
        title: '请输入内容',
        icon: 'none'
      });
      return;
    }

    // 去除末尾的换行符和空格，但保留中间的换行和空格
    content = content.replace(/[\n\s]+$/g, '');

    // 更新聊天列表（保持原有的更新逻辑）
    this.setData({
      messages: [...this.data.messages, content],
      inputValue: ''
    });
  }
}); 